﻿using System;
using System.Collections.Generic;
using Windows.UI.Xaml;

namespace CrateMayhem.WinRT.Common
{
    public static class UriResourceExtensions
    {
        private static readonly Dictionary<string, ResourceDictionary> resources 
            = new Dictionary<string, ResourceDictionary>();
        
        public static T Get<T>(this Uri uri, string key)
        {
            if (!resources.ContainsKey(uri.ToString())) 
                resources.Add(uri.ToString(), new ResourceDictionary {Source = uri});
            var dictionary = resources[uri.ToString()];
            return (T)dictionary[key];
        }
    }
}
